using System;
namespace Legend
{
    /// <summary>
    /// Generates random numbers using the <see cref="System.Random" class.
    /// </summary>
    public class DefaultRandomNumberGenerator
        : IRandomNumberGenerator
    {
        private const int RandomIntegerMaxValue = int.MaxValue - 1;
        private Random randomizer;

        public DefaultRandomNumberGenerator()
        {
            this.randomizer = new Random();
        }

        /// <summary>
        /// Gets a random integer number.
        /// </summary>
        /// <param name="minValue">The lowest value to generate (inclusive).</param>
        /// <param name="maxValue">The highest possible value to generate (inclusive).</param>
        /// <returns></returns>
        public int GetRandomInteger(int minValue, int maxValue)
        {
            Require.ThatArgument(minValue).Named("minValue").IsInRange(int.MinValue, maxValue);
            Require.ThatArgument(maxValue).Named("maxValue").IsInRange(int.MinValue, RandomIntegerMaxValue);

            return this.randomizer.Next(minValue, maxValue + 1);
        }

        /// <summary>
        /// Gets a random floating point number between zero and one.
        /// </summary>
        public double GetRandomFloatingPointNumber()
        {
            return this.randomizer.NextDouble();
        }
    }
}
